package com.chinags.system.report.controller;

import java.util.List;

import com.chinags.framework.util.ShiroUtils;
import com.chinags.system.report.domain.TJcJcbg;
import com.chinags.system.report.service.ITJcJcbgService;
import com.chinags.system.testingfacility.domain.TJcJcjg;
import com.chinags.system.testingfacility.service.ITJcJcjgService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.chinags.common.annotation.Log;
import com.chinags.common.enums.BusinessType;
import com.chinags.common.core.controller.BaseController;
import com.chinags.common.core.page.TableDataInfo;
import com.chinags.common.core.domain.AjaxResult;
import com.chinags.common.utils.poi.ExcelUtil;
import org.springframework.web.multipart.MultipartFile;

/**
 * 检测报告基本 信息操作处理
 * 
 * @author liut
 * @date 2019-06-20
 */
@Controller
@RequestMapping("/system/tJcJcbg")
public class TJcJcbgController extends BaseController
{
    private String prefix = "system/report/tJcJcbg";
	
	@Autowired
	private ITJcJcbgService tJcJcbgService;
	@Autowired
	private ITJcJcjgService tJcJcjgService;

	@RequiresPermissions("system:tJcJcbg:view")
	@GetMapping()
	public String tJcJcbg()
	{
	    return prefix + "/tJcJcbg";
	}
	
	/**
	 * 查询检测报告基本列表
	 */
	@RequiresPermissions("system:tJcJcbg:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TJcJcbg tJcJcbg)
	{
		startPage();
        List<TJcJcbg> list = tJcJcbgService.selectTJcJcbgList(tJcJcbg);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出检测报告基本列表
	 */
	@RequiresPermissions("system:tJcJcbg:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TJcJcbg tJcJcbg)
    {
    	List<TJcJcbg> list = tJcJcbgService.selectTJcJcbgList(tJcJcbg);
        ExcelUtil<TJcJcbg> util = new ExcelUtil<TJcJcbg>(TJcJcbg.class);
        return util.exportExcel(list, "tJcJcbg");
    }
	
	/**
	 * 新增检测报告基本
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存检测报告基本
	 */
	@RequiresPermissions("system:tJcJcbg:add")
	@Log(title = "检测报告基本", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TJcJcbg tJcJcbg)
	{		
		return toAjax(tJcJcbgService.insertTJcJcbg(tJcJcbg));
	}

	/**
	 * 修改检测报告基本
	 */
	@GetMapping("/edit/{reportId}")
	public String edit(@PathVariable("reportId") Long reportId, ModelMap mmap)
	{
		TJcJcbg tJcJcbg = tJcJcbgService.selectTJcJcbgById(reportId);
		mmap.put("tJcJcbg", tJcJcbg);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存检测报告基本
	 */
	@RequiresPermissions("system:tJcJcbg:edit")
	@Log(title = "检测报告基本", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TJcJcbg tJcJcbg)
	{		
		return toAjax(tJcJcbgService.updateTJcJcbg(tJcJcbg));
	}
	
	/**
	 * 删除检测报告基本
	 */
	@RequiresPermissions("system:tJcJcbg:remove")
	@Log(title = "检测报告基本", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(tJcJcbgService.deleteTJcJcbgByIds(ids));
	}
	/***
	 * 导入检测报告基本信息
	 */

	@RequiresPermissions("system:tJcJcbg:import")
	@PostMapping("/importData")
	@ResponseBody
	public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
	{
		ExcelUtil<TJcJcbg> util = new ExcelUtil<TJcJcbg>(TJcJcbg.class);
		List<TJcJcbg> tJcJcbgList = util.importExcel(file.getInputStream());
		String operName = ShiroUtils.getSysUser().getLoginName();
		String message = tJcJcbgService.importUser(tJcJcbgList, updateSupport, operName);
		return AjaxResult.success(message);
	}
	/**
	 * 下载模板
	 *
	 * */
	@RequiresPermissions("system:tJcJcbg:view")
	@GetMapping("/importTemplate")
	@ResponseBody
	public AjaxResult importTemplate()
	{
		ExcelUtil<TJcJcbg> util = new ExcelUtil<TJcJcbg>(TJcJcbg.class);
		return util.importTemplateExcel("检测报告基本信息数据");
	}
	/**
	 * 查看详细
	 */
	@GetMapping("/detail/{reportId}")
	public String detail(@PathVariable("reportId") Long reportId, ModelMap mmap)
	{
		mmap.put("name", "tJcJcbg");
		mmap.put("tJcJcbg", tJcJcbgService.selectJobLogById(reportId));
		return prefix + "/detail";
	}
	@RequiresPermissions("system:tJcJcbg:list")
	@PostMapping("/codeTo")
	@ResponseBody
	public List<TJcJcjg> codeTo(TJcJcjg tJcJcjg)
	{

		List<TJcJcjg> list = tJcJcjgService.selectTJcJcjgList(tJcJcjg);
		return list;
	}
	/**表格页面*/
	@GetMapping("/radio")
	public String radio()
	{
		return prefix + "/radio";
	}


}
